package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.Settings;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.mapper.SettingsMapper;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Service
public class settingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsMapper settingsMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public Settings findSettings(Long loginUserId) {
        QueryWrapper<Settings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",loginUserId);
        return settingsMapper.selectOne(queryWrapper);
    }

    @Override
    public void saveSettings(Settings settings) {
        Settings settingsUser = findSettings(settings.getUserId());
        if (null !=settingsUser){
            settings.setId(settingsUser.getId());
            settingsMapper.updateById(settings);
        }else {
            settingsMapper.insert(settings);
        }
    }

    @Override
    public void changMobile(String phone, Long loginUSerId) {
        User user = new User();
        user.setId(loginUSerId);
        user.setMobile(phone);
        userMapper.updateById(user);
    }
}
